﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CMSService
{
    /// <summary>
    /// 专题
    /// </summary>
    public class SpecialSubjectService : ICMS.ISpecialSubject
    {
        DavidDB.ADO.DBManager db = null;
        private SpecialSubjectService()
        {
            db = new DavidDB.ADO.DBManager();
        }
        public SpecialSubjectService(DavidDB.ADO.DBManager db)
        {
            this.db = db;
        }




        /// <summary>
        /// 获取一个网站专题
        /// </summary>
        /// <param name="id">专题编号</param>
        /// <returns>网站专题，如果没有，返回Null</returns>
        public CMSModel.SpecialSubject GetModel(int id)
        {
            CMSModel.SpecialSubject returnValue = new CMSModel.SpecialSubject();
            returnValue.Id = id;
            returnValue = db.GetModel(returnValue);
            return returnValue;
        }
        /// <summary>
        /// 删除一个网站专题
        /// </summary>
        /// <param name="id">专题编号</param>
        /// <returns>成功删除，返回0，没有当前专题，返回-1</returns>
        public int Delete(int id)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            CMSModel.SpecialSubject model = new CMSModel.SpecialSubject();
            model.Id = id;
            db.Delete(model);
            return returnValue;
        }
        /// <summary>
        /// 增加一个网站专题
        /// </summary>
        /// <param name="announcement">网站专题实体</param>
        /// <returns>增加成功，返回0</returns>
        public int Insert(CMSModel.SpecialSubject specialSubject)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            db.Insert(specialSubject);
            return returnValue;
        }
        /// <summary>
        /// 编辑一个专题
        /// </summary>
        /// <param name="announcement">编辑完成的专题</param>
        /// <returns>编辑成功，返回0</returns>
        public int Edit(CMSModel.SpecialSubject specialSubject)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            db.Edit(specialSubject);
            return returnValue;
        }
        /// <summary>
        /// 到底最新的count条记录
        /// </summary>
        /// <param name="count">查询条数</param>
        /// <returns>如果记录足够多，返回count条，否则，返回所有记录</returns>
        public List<CMSModel.SpecialSubject> GetList(int count)
        {
            List<CMSModel.SpecialSubject> lists = new List<CMSModel.SpecialSubject>();
            var query = db.GetTopList(count, new CMSModel.SpecialSubject());
            foreach (CMSModel.SpecialSubject model in query)
            {
                lists.Add(model);
            }
            return lists;
        }
    }
}
